using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class FingerUIItem : XObjBase
{
    public Image image;
    // Start is called before the first frame update
    private void OnEnable()
    {
        Facade.Instance.RegistEvent(EventID.Finger_Index, OnFingerIndexChange);
    }

    private void OnDisable()
    {
        Facade.Instance.UnRegistEvent(EventID.Finger_Index, OnFingerIndexChange);
    }

    private  void OnFingerIndexChange(object arg){
        var index = (int)arg;
        if(_fingerIndex == index)
        {
            image.color = Color.black;
        }
        else
        {
            image.color = Color.gray;
        }
    }
    // Update is called once per frame
    void Update()
    {
        
    }
    private int _fingerIndex;
    public void SetFingerIndex(int fingerIndex)
    {
        _fingerIndex = fingerIndex;
        var rect = image.GetComponent<RectTransform>();
        switch (_fingerIndex)
        {
            case 0:
                rect.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, 140);
                break;
            case 1:
                rect.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, 170);
                break;
            case 2:
                rect.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, 190);
                break;
            case 3:
                rect.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, 170);
                break;
            case 4:
                rect.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, 170);
                break;
            case 5:
                rect.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, 190);
                break;
            case 6:
                rect.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, 170);
                break;
            case 7:
                rect.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, 140);
                break;
            default:
                Debug.LogError("Can not find finger index:" + _fingerIndex);
                break;
        }
    }
}
